﻿using MediatR;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;

namespace Extensions.DomainEvent;

public class BaseEntity : IDomainEvents
{
    // 这边是由具体的实体来继承的  所有不映射
    [NotMapped] private readonly List<INotification> _events = new();

    /// <summary>
    /// 获取事件
    /// </summary>
    /// <returns></returns>
    public IEnumerable<INotification> GetDomainEvents()
    {
        return _events;
    }

    /// <summary>
    /// 添加事件
    /// </summary>
    /// <param name="eventItem"></param>
    /// <exception cref="System.NotImplementedException"></exception>
    public void AddDomainEvent(INotification eventItem)
    {
        _events.Add(eventItem);
    }

    /// <summary>
    /// 清除事件
    /// </summary>
    /// <exception cref="System.NotImplementedException"></exception>
    public void ClearDomainEvents()
    {
        _events.Clear();
    }
}